extends Area2D

const HitEffect = preload("res://Effects/HitEffect.tscn")

onready var timer = $Timer
onready var col = get_node("CollisionShape2D")
var invincible = false setget set_invincible

signal invincibility_started
signal invincibility_ended

func set_invincible(val):
	invincible = val
	if invincible:
		emit_signal("invincibility_started") 
	else:
		emit_signal("invincibility_ended")

func start_invincibility(duration):
	self.invincible = true
	timer.start(duration)
	
func create_hit_effect():
	var effect = HitEffect.instance()
	var main = get_tree().current_scene
	main.add_child(effect)
	effect.global_position = global_position 

func _on_Timer_timeout():
	self.invincible = false

func _on_Hurtbox_invincibility_started():
#	monitorable = false
#	monitoring = false
	set_deferred("monitoring", false) 
#	call_deferred("set","monitorable",false)
	print('开始无敌',monitoring)

func _on_Hurtbox_invincibility_ended():
	set_deferred("monitoring", true) 

